package com.lv.lucence;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.FSDirectory;

import java.io.File;
import java.io.IOException;

/**
 * Created by lvjilei on 2018/3/29.
 */
public class TxtIndexSeacher {

    public static void  main(String[] args){
        try {
            File indexFileDir = new File("/Library/mySource/lucence/index");
            IndexSearcher indexSearcher =
                    new IndexSearcher(DirectoryReader.open(FSDirectory.open(indexFileDir.toPath())));

            /*Term term = new Term("name","dasdsa");
            TermQuery termQuery = new TermQuery(term);*/

            QueryParser queryParser = new QueryParser("path",new StandardAnalyzer());
            queryParser.parse("lucence");




            /*for (ScoreDoc doc : topDocs.scoreDocs){
                Document document = indexSearcher.doc(doc.doc);
                System.out.println("name = " + document.getField("name"));
                System.out.println("path = " + document.getField("path"));
                System.out.println("content = " + document.getField("content") +"\n\n\n\n\n");
            }*/
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

}
